package cs4280.ass2.util;

import org.apache.commons.lang.StringUtils;

import cs4280.ass2.entity.Ticket;
import cs4280.ass2.exception.ValidateException;

public class TicketUtils {
	
	public static void validate(Ticket ticket) throws ValidateException {
		if (ticket.getScheduleSeatDetailId() < 0L) {
			throw new ValidateException("message.error.validate.ticket.scheduleSeatDetailId.negativeValue");
		}
		if (!isValidTicketStatus(ticket)) {
			throw new ValidateException("message.error.validate.ticket.ticketStatus.invalid");
		}
	}
	
	public static boolean isValidTicketStatus(Ticket ticket) {
		return (ticket.getTicketStatus().equals(Ticket.TICKET_STATUS_ACTIVE) ||
		        ticket.getTicketStatus().equals(Ticket.TICKET_STATUS_PENDING)||
		        ticket.getTicketStatus().equals(Ticket.TICKET_STATUS_REFUNDED));
	}
	
	public static boolean isPendingRefund(Ticket ticket){
		return (StringUtils.equals(ticket.getTicketStatus(), Ticket.TICKET_STATUS_PENDING));
	}
	
	public static boolean isRefunded(Ticket ticket){
		return (StringUtils.equals(ticket.getTicketStatus(), Ticket.TICKET_STATUS_REFUNDED));
	}
}
